﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace System
{
    [Serializable]
    [DebuggerDisplay("state:{state},  message:{message}")]
    public class AjaxResult
    {
        /// <summary>
        /// 操作结果类型 ResultType
        /// </summary>
        public string state { get; set; }
        /// <summary>
        /// 获取 消息内容
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// 获取 返回数据
        /// </summary>
        public object data { get; set; }
    }
    /// <summary>
    /// 表示 ajax 操作结果类型的枚举
    /// </summary>
    public enum ResultType
    {
        /// <summary>
        /// 消息结果类型
        /// </summary>
        info,
        /// <summary>
        /// 成功结果类型
        /// </summary>
        success,
        /// <summary>
        /// 警告结果类型
        /// </summary>
        warning,
        /// <summary>
        /// 异常结果类型
        /// </summary>
        error,
        /// <summary>
        /// 未知
        /// </summary>
        unknown
    }
    public class ShowMessage
    {
        public static string Success(string message)
        {
            return new AjaxResult { state = ResultType.success.ToString(), message = message }.ToJson();
        }
        public static string Success(string message, object data)
        {
            return new AjaxResult { state = ResultType.success.ToString(), message = message, data = data }.ToJson();
        }
        public static string Error(string message)
        {
            return new AjaxResult { state = ResultType.error.ToString(), message = message }.ToJson();
        }
    }
}
